package com.js.service.impl;

import com.js.entity.DStudent;
import com.js.dao.DStudentDao;
import com.js.service.DStudentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import java.util.List;
import javax.annotation.Resource;

/**
 * (DStudent)表服务实现类
 *
 * @author makejava
 * @since 2022-06-15 14:06:58
 */
@Service("dStudentService")
public class DStudentServiceImpl implements DStudentService {
    @Resource
    private DStudentDao dStudentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param sId 主键
     * @return 实例对象
     */
    @Override
    public DStudent queryById(Integer sId) {
        return this.dStudentDao.queryById(sId);
    }

    /**
     * 分页查询
     *
     * @param dStudent 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<DStudent> queryByPage(DStudent dStudent, PageRequest pageRequest) {
        long total = this.dStudentDao.count(dStudent);
        return new PageImpl<>(this.dStudentDao.queryAllByLimit(dStudent, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param dStudent 实例对象
     * @return 实例对象
     */
    @Override
    public DStudent insert(DStudent dStudent) {
        this.dStudentDao.insert(dStudent);
        return dStudent;
    }

    /**
     * 修改数据
     *
     * @param dStudent 实例对象
     * @return 实例对象
     */
    @Override
    public DStudent update(DStudent dStudent) {
        this.dStudentDao.update(dStudent);
        return this.queryById(dStudent.getSId());
    }

    /**
     * 通过主键删除数据
     *
     * @param sId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer sId) {
        return this.dStudentDao.deleteById(sId) > 0;
    }
    /**
    * 查询所有
    * @return 列表
    */
    @Override
    public List<DStudent> queryAll(){
        return this.dStudentDao.queryAll();
    }
}
